package com.github.alenfive.rocketapidemo.config;

import com.github.alenfive.rocketapi.extend.IUserAuthorization;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.stereotype.Component;
import org.thymeleaf.util.StringUtils;

/**
 *  默认用户权限验证
 */
@Component
public class DefaultUserAuthorization implements IUserAuthorization {

    private static final Logger log = LogManager.getLogger(DefaultUserAuthorization.class);

    /**
     * 用户名密码验证  返回值不为null即校验成功
     * @param username
     * @param password
     * @return
     */
    @Override
    public String validate(String username, String password) {
        if ( "admin".equals(username)){
            log.info("用户名密码验证成功");
        }
        return StringUtils.isEmpty(username)?"admin":username;
    }
}